import java.util.*;
public class Main {
    //PRIMERA PRUEBA CASO 1
    private static int cantCubos, cantDimensiones, indiceClave, indiceSum;
    private static Scanner consola = new Scanner(System.in);
    private static int cubos[][];
    private static StringBuilder sb = new StringBuilder();

    public static void main(String args[]) {
        while (consola.hasNextLine()) {
            //Mientras tenga un entero mas
            cantCubos = consola.nextInt();
            cantDimensiones = indiceSum = consola.nextInt();
            indiceClave = indiceSum + 1;
            cubos = new int[cantCubos][cantDimensiones + 2];

            //Cargo y ordenos los cubos
            for (int i = 0; i < cantCubos; i++) {
                cubos[i][indiceClave] = 2147483647;
                cubos[i][indiceSum] = 0;
                for (int j = 0; j < cantDimensiones; j++) {
                    cubos[i][j] = consola.nextInt();
                    cubos[i][indiceSum] += cubos[i][j];
                }
                Arrays.sort(cubos[i]);
                cubos[i][indiceClave] = i + 1;
            }
            cubos = reordenar2();
            armar();
            int a = 0;
        }
        sb.deleteCharAt(sb.length() - 1);
        System.out.print(sb);
    }

    private static int[][] reordenar2() {
        int retorno[][] = new int[cantCubos][cantDimensiones], indiceMenor;

        for (int i = 0; i < cantCubos; i++) {
            indiceMenor = 0;
            while (cubos[indiceMenor] == null) {
                indiceMenor++;
            }
            for (int j = 0; j < cantCubos; j++) {
                if (cubos[j] == null) {
                    continue;
                }
                if (cubos[j][indiceSum] < cubos[indiceMenor][indiceSum]) {
                    indiceMenor = j;
                }
            }
            retorno[i] = cubos[indiceMenor];
            cubos[indiceMenor] = null;
        }
        return retorno;
    }

    private static int[][] reordenar() {

        int posicion, salida[][], indiceMenor;
        salida = new int[cantCubos][cantDimensiones];
        for (int i = 0; i < cantCubos; i++) {
            indiceMenor = 0;

            for (int j = 0; j < cantCubos; j++) {

                if (cubos[j] == null) {
                    continue;
                }
                posicion = 0;

                while (cubos[indiceMenor] == null
                        && indiceMenor < cantCubos) {
                    indiceMenor++;
                }

                while (indiceMenor != j
                        && cubos[indiceMenor][posicion] == cubos[j][posicion]
                        && posicion < cantDimensiones) {
                    posicion++;
                }

                if (cubos[j] != null
                        && cubos[indiceMenor][posicion] > cubos[j][posicion]) {
                    indiceMenor = j;
                }
            }
            salida[i] = cubos[indiceMenor];
            cubos[indiceMenor] = null;
        }
        return salida;
    }

    private static void armar() {
        boolean primeraVez = true;
        String st = "";
        int cantidad = 0, ultimoIndice = 0;

        for (int i = 0; i + 1 < cantCubos; i++) {
            if (entra(ultimoIndice, i + 1)) {
                if (primeraVez) {
                    st += cubos[ultimoIndice][indiceClave] + " " + cubos[i + 1][indiceClave];
                    cantidad += 2;
                    primeraVez = false;
                } else {
                    st += " " + cubos[i + 1][indiceClave];
                    cantidad++;
                }
                ultimoIndice = i + 1;
            }
        }
        sb.append(cantidad).append("\n").append(st).append("\n");
    }

    private static boolean entra(int a, int b) {
        for (int i = 0; i < cantDimensiones; i++) {
            if (cubos[a][i] >= cubos[b][i]) {
                return false;
            }
        }
        return true;
    }
}